﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using RootLibrary.WPF.Localization;

namespace GlobalizationTools
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.AppStarting;

            LocalizeDictionary.Instance.Culture = CultureInfo.CurrentCulture;

            base.OnStartup(e);

            this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;
            MessageBox.Show(this.MainWindow, ex.Message, LocalizationResource.Error, MessageBoxButton.OK, MessageBoxImage.Error);
        }

        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(this.MainWindow, e.Exception.Message, LocalizationResource.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            e.Handled = true;
        }

    }
}
